package com.ys.peony.rolecontrol.ui;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.ys.peony.R;
import com.ys.peony.base.contract.BasicActivity;
import com.ys.peony.rolecontrol.RoleControlContract;
import com.ys.peony.rolecontrol.entity.Component;
import com.ys.peony.rolecontrol.entity.Info;
import com.ys.peony.rolecontrol.entity.Layout;
import com.ys.peony.rolecontrol.entity.Widget;
import com.ys.peony.rolecontrol.presenter.RoleControlPresenter;
import com.ys.peony.utils.ImageLoadUtils;
import com.zhouwei.mzbanner.MZBannerView;
import com.zhouwei.mzbanner.holder.MZHolderCreator;
import com.zhouwei.mzbanner.holder.MZViewHolder;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class ConfigActivity extends BasicActivity<RoleControlContract.iRoleControlView, RoleControlPresenter> {
    @BindView(R.id.rootview)
    FrameLayout rootview;
    @BindView(R.id.banner)
    MZBannerView mMZBanner;
    private List<Component> components;
    private List<Layout> layouts;
    private List<Widget> widgets;
    private Info info;

    @Override
    protected int getContentResId() {
        return R.layout.activity_config;
    }

    @Override
    protected void initView() {
        super.initView();
        initUILayout();

    }

    @Override
    protected RoleControlPresenter initPresenter() {
        return new RoleControlPresenter(this);
    }

    @Override
    public void onFail(String msg) {

    }

    private void initUILayout() {
        //presenter.parseRoleConfig();
        ViewGroup viewGroup = presenter.getUiLayout();
        if(viewGroup != null) {
            rootview.removeAllViews();
            rootview.addView(viewGroup);
        }
        /*mMZBanner.setIndicatorVisible(true);
        List<String> bannerImgs = new ArrayList<>();
        bannerImgs.add("file:///android_asset/banner2.png");
        bannerImgs.add("file:///android_asset/banner3.png");
        bannerImgs.add("file:///android_asset/banner2.png");
        mMZBanner.setPages(bannerImgs, new MZHolderCreator<BannerViewHolder>() {
            @Override
            public BannerViewHolder createViewHolder() {
                return new BannerViewHolder();
            }
        });
        mMZBanner.start();*/

    }

    public static class BannerViewHolder implements MZViewHolder<String> {
        private ImageView mImageView;

        @Override
        public View createView(Context context) {
            View view = LayoutInflater.from(context).inflate(R.layout.banner_item, null);
            mImageView = (ImageView) view.findViewById(R.id.banner_image);
            return view;
        }

        @Override
        public void onBind(Context context, int position, String data) {
            ImageLoadUtils.showImg(mImageView, data);
        }
    }
}
